package com.gem.day14;

import java.io.*;
import java.util.UUID;

import org.fluttercode.datafactory.impl.DataFactory;

/**
 * 本类用来演示Java操作基本类型的IO流
 * DataInputStream/DataOutputStream
 * 
 * @author easonsy
 * 2020年8月6日 上午11:22:02
 */
public class DataInputStreamDemo {
	public static void main(String[] args) {
		DataFactory df = new DataFactory();
		User u = null;
		for (int i = 0; i < 10; i++) {
			u = new User(df.getFirstName() + " " + df.getLastName());
			System.out.println(u);
		}

		System.out.println(UUID.randomUUID().toString());
	}
}

class User {
	private Long id;
	private String name;

	public User(String name) {
		this.id = getUuid() + 1;
		this.name = name;
		setUuid(id);
	}

	@Override
	public String toString() {
		return id + "-" + name;
	}

	private Long getUuid() {
		Long result = 0L;
		try (DataInputStream dis = new DataInputStream(new FileInputStream("D:\\temp\\data.dat"))) {
			result = dis.readLong();
		} catch (Exception e) {

		}
		return result;
	}

	private void setUuid(Long number) {
		try (DataOutputStream dos = new DataOutputStream(new FileOutputStream("D:\\temp\\data.dat"))) {
			dos.writeLong(number);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
